import face_recognition
import cv2

# 读取图片
image = cv2.imread('../img/two.jpg')

# 转换为RGB格式
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# 使用face_locations函数获取人脸位置
face_locations = face_recognition.face_locations(rgb_image)

# 绘制圆形标记出人脸位置
for top, right, bottom, left in face_locations:
    # 在每个位置绘制圆形标记
    cv2.circle(image, (left, top), 5, (0, 255, 0), -1)  # 左上角
    cv2.circle(image, (right, top), 5, (0, 255, 0), -1)  # 右上角
    cv2.circle(image, (left, bottom), 5, (0, 255, 0), -1)  # 左下角
    cv2.circle(image, (right, bottom), 5, (0, 255, 0), -1)  # 右下角

    # 在每个位置显示位置信息
    cv2.putText(image, f"Top: {top}", (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
    cv2.putText(image, f"Right: {right}", (right, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
    cv2.putText(image, f"Bottom: {bottom}", (left, bottom + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
    cv2.putText(image, f"Left: {left}", (right, bottom + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)

# 显示标记后的图片
cv2.imshow('Face Locations', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
